using System;
using Microsoft.Xna.Framework;
using Rocuna.Controls.Interfaces;

namespace Rocuna.Controls.Shapes
{
    /// <summary>
    /// Base class for circle shape.
    /// </summary>
    public class Circle : ISurface
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Circle"/> class.
        /// </summary>
        public Circle(int x, int y, int radius)
        {
            Center = new Point(x, y);
            Radius = radius;
        }

        #region Properties

        /// <summary>
        /// Gets or sets the center.
        /// </summary>
        /// <value>
        /// The center.
        /// </value>
        public Point Center { get; set; }

        /// <summary>
        /// Gets or sets the radius.
        /// </summary>
        /// <value>
        /// The radius.
        /// </value>
        public int Radius { get; set; }

        #endregion

        #region Implementation of ISurface

        /// <summary>
        /// Determines whether the instance contains the specified point.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <returns>
        ///   <c>true</c> if the instance contains the specified point; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(Vector2 position)
        {
            return ((Math.Abs(position.X - Center.X) < Radius) && (Math.Abs(position.Y - Center.Y) < Radius));
        }

        /// <summary>
        /// Determines whether the instance contains the specified x and y.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <returns>
        ///   <c>true</c> if the instance contains the specified x and y; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(float x, float y)
        {
            var position = new Vector2(x, y);
            return Contains(position);
        }

        /// <summary>
        /// Converting to rectangle.
        /// </summary>
        /// <returns></returns>
        public Rectangle ToRectangle()
        {
            var rec = new Rectangle(Center.X - Radius, Center.Y - Radius, Radius * 2, Radius * 2);
            return rec;
        }

        #endregion
    }
}